<template>
    <div class="innerPage" v-if="page">
        <div class="inner-img">
            <div class="img-bg" v-if="VideoIndexOf(Contentlist.cover || Contentlist.antsCollectionBlindBox.image)"
                :style="'background-image:url(' + Contentlist.cover || Contentlist.antsCollectionBlindBox.image + ') '">
                <div class="img-status" v-if="!paytype">
                    <img src="@/assets/image/status.png" alt="">
                </div>
                <img :src="Contentlist.cover || Contentlist.antsCollectionBlindBox.image" alt="">
            </div>
            <div class="videoContainer" v-else>
                <div class="img-status" v-if="!paytype">
                    <img src="@/assets/image/status.png" alt="">
                </div>
                <vdeo :collection='Contentlist.files || Contentlist.antsCollectionBlindBox.files' class="video" />
            </div>
        </div>
        <div class="bottom-bg"></div>
        <van-row justify="center">
            <van-col span="24" class="inner-title">
                <h1>{{ Contentlist.name || Contentlist.antsCollectionBlindBox.name }}</h1>
            </van-col>
            <van-col v-if="Contentlist.userCode">
                <p class="linercolor">{{ Contentlist.userCode || Contentlist.antsCollectionBlindBox.userCode }}</p>
            </van-col>
            <!-- <van-col span="24" class="inner-title">
                <div class="Limit-warp">
                    <span>限量</span>
                    <span>{{ Contentlist.collection.totalNumber ? Contentlist.collection.totalNumber : "0" }}份</span>
                </div>
                <div class="Limit-warp">
                    <span>剩余</span>
                    <span>{{ Contentlist.collection.surplusNumber ? Contentlist.collection.surplusNumber : "0" }}份</span>
                </div>
            </van-col> -->
        </van-row>
        <div>
            <van-row justify="end" class="colletion-authon">
                <van-col span="12">结束时间 : </van-col>
                <van-col span="12" class="right">
                    <span>{{ Contentlist.endTime }}</span>
                </van-col>
            </van-row>
            <van-row justify="end" class="colletion-authon">
                <van-col span="12">竞拍方 : </van-col>
                <van-col span="12" class="right">
                    <span>{{ Contentlist.type == 1 ? Contentlist.mechanism : '宽情' }}</span>
                </van-col>
            </van-row>
            <van-row justify="end" class="colletion-authon">
                <van-col span="12">当前最高价 : </van-col>
                <van-col span="12" class="right">
                    <span>{{ Contentlist.maxPrice }}</span>
                </van-col>
            </van-row>
            <div class="collect-info">
                规则说明
            </div>
            <div class="story" v-if="formData.status">
                <p>1.每次竞价成功，竞价金额会被冻结，直到竞拍结束</p>
                <p>2.竞拍结束时，出价最高的竞价者可购得该藏品</p>
            </div>
            <div class="story" v-else>
                <p>1.竞拍者需支付竞拍成交价的{{ formData.ServiceCharge * 100 }}%作为手续费</p>
                <p>2.竞拍成交价为截至竞拍结束时竞价者的最高出价</p>
            </div>
        </div>
        <div class="collect-info">
            藏品信息
        </div>
        <van-row justify="end" class="colletion-authon">
            <van-col span="12">创作者</van-col>
            <van-col span="12" class="right">
                <span>{{ Contentlist.serviceProvider || Contentlist.antsCollectionBlindBox.serviceProvider }}</span>
            </van-col>
        </van-row>
        <van-row justify="end" class="colletion-authon">
            <van-col span="12">发行方</van-col>
            <van-col span="12" class="right">
                <span>{{ Contentlist.mechanism || Contentlist.antsCollectionBlindBox.mechanism }}</span>
            </van-col>
        </van-row>
        <van-row justify="end" class="colletion-authon">
            <van-col span="6">合约地址</van-col>
            <van-col span="18" class="right">
                <p>{{ Contentlist.assetId ? Contentlist.assetId : '未上链' }}</p>
                <img src="../../assets/image/icon/copids.png" alt="" @click="copy">
            </van-col>
        </van-row>
        <van-row justify="end" class="colletion-authon" v-if="!paytype">
            <van-col span="12">中签可购</van-col>
            <van-col span="12" class="right">
                <span>{{ Contentlist.appName || Contentlist.antsCollectionBlindBox.appName }}</span>
            </van-col>
        </van-row>
        <div class="collect-info">
            藏品详情
        </div>
        <div class="story">
            <img :src="Contentlist.certificatePictureUrl" alt="" @click="openImg(Contentlist.certificatePictureUrl)">
            <!-- <div class="certificate">
                <img src="../../assets/image/certificate-header.png" alt="" class="certificate-img">
                <h1>数字藏品鉴定证书</h1>
                <div class="certificate-time">
                    <p>区块链网络全球通用协调时间</p>
                    <p>Wed Jan 16 08:50:20 UTC 2019</p>
                </div>
                <div class="certificate-code">
                    <img src="../../assets/image/tabbg.png" alt="">
                    <p>扫码查看作品存证详情</p>
                </div>
                <div class="certificate-content">
                    <img src="../../assets/image/border.png" alt="" class="borders">
                    <div>
                        <p>藏品鉴定ID：</p>
                        <p>A4564S</p>
                    </div>
                    <div>
                        <p>数字藏品名称：</p>
                        <p>后台配置的藏品名称</p>
                    </div>
                    <div>
                        <p>鉴定人姓名：</p>
                        <p>后台配置的鉴定人姓名</p>
                    </div>
                    <div>
                        <p>鉴定人职业：</p>
                        <p>后台配置的鉴定人职业</p>
                    </div>
                    <div>
                        <p>存证时间：</p>
                        <p>2022年12月01日 15:59:59</p>
                    </div>
                    <div>
                        <p>存证平台：</p>
                        <p>区块链存证网站链接</p>
                    </div>
                    <img src="../../assets/image/border.png" alt="" class="borders">
                </div>
                <p class="statement">区块链电子存证</p>
            </div> -->
            <div v-html="Contentlist.story">
            </div>
        </div>
        <!-- <div class="story" v-html="Contentlist.story || Contentlist.antsCollectionBlindBox.story"></div> -->
        <div class="collect-info">
            购买须知
        </div>
        <div class="story"> 数字藏品为虚拟商品，而非实物，仅限实名认证的中国大陆用户购买，数字藏品的版权由发行方或原创作者拥有，除另外取得版权拥有者书面同意外，
            用户不得将数字藏品用于任何商业用途。本商品一经售出，不支持退换。本商品源文件不支持本地下载，请勿对数字藏品进行炒作/场外交易/欺诈或以任何其他非法方式进行使用。</div>
        <!-- v-if="Contentlist.isLogUserSell == 0" -->
        <div class="fiexd-footer" v-if="formData.status">
            <van-cell-group inset>
                <van-field v-model="paydata.amount" type="tel" placeholder="请输入竞拍价格" />
            </van-cell-group>
            <div class="footer">
                <van-row justify="space-between" class="fsb">
                    <van-col span="12">
                        <span class="price">￥{{ Contentlist.maxPrice }}</span>
                    </van-col>
                    <van-col span="12" class="right">
                        <van-button type="primary" @click="openPwd(4)" class="buy">
                            <span>立即竞拍</span>
                        </van-button>
                    </van-col>
                </van-row>
            </div>
        </div>
        <div class="fiexd-footer" v-if="!formData.status && Contentlist.type == 1">
            <div class="footer">
                <van-row justify="space-between" class="fsb">
                    <van-col span="24" class="right">
                        <van-button type="primary" @click="openPwd(6)" class="buys">
                            <span>取消竞拍</span>
                        </van-button>
                    </van-col>
                </van-row>
            </div>
        </div>
    </div>
    <Pwdwarp ref="PwdShow" :paydata="paydata" @updata:load="onLoad" />
</template>
<script>
import { reactive, computed, onMounted, defineComponent, onBeforeMount, ref, watch } from 'vue'
import Clipboard from 'clipboard';
import useClipboard from 'vue-clipboard3'
import { useStore } from "vuex";
import { useRouter } from "vue-router"
import { VideoIndexOf, formatPhoneNumber } from "@/utils/phone";
import Pwdwarp from "@/components/pwd.vue";
import { collectionInfo, needSynthesisList, shopping, findByBlindBox, sellgetInfo, getCollectionInfotype, orderDetail, collectionAuctionCancel, listAuction } from "@/api/public";
import { Toast, ImagePreview } from "vant";
import vueVideo from "@/components/vueVideo.vue";
import vdeo from "@/components/video.vue";
import { async } from 'q';
export default {
    components: {
        Pwdwarp, vueVideo, vdeo
    },
    setup(props) {
        onMounted(async () => {
            onLoad()
            await store.dispatch('user/getUserAll')
        })
        const store = useStore();
        const router = useRouter()
        const page = ref(false)
        const paytype = ref(true)
        const { toClipboard } = useClipboard()
        const Contentlist = ref({})
        const Available = ref([])
        const user_info = computed(() => {
            return store.getters.user_info
        })
        const formData = reactive({
            type: 4,
            amount: '',
            status: ''
        })
        const openImg = (url) => {
            ImagePreview([url]);
        }
        const onLoad = async () => {

            listAuction().then(res => {
                formData.ServiceCharge = res.data.data.handling_fee
                formData.integral = res.data.data.markup_integral
            })
            Toast.loading({
                message: '数据加载中...',
                forbidClick: true,
            });
            const data = { sellId: router.currentRoute.value.query.id }
            const res = router.currentRoute.value.query.type ? await orderDetail({ id: router.currentRoute.value.query.id }) : await sellgetInfo(data)
            if (res.data.success) {
                page.value = true
                Toast.clear()
                Contentlist.value = res.data.data
                formData.status = user_info.value.id != res.data.data.userId
            }
        }
        const paydata = ref({
            id: router.currentRoute.value.query.id,
            type: 4,
            amount: ''
        })
        const PwdShow = ref(null)
        const openPwd = async (type) => {
            paydata.value.type = type
            if (type == 4) {
                if (paydata.value.amount <= Contentlist.value.maxPrice) {
                    Toast("您输入的价格低于当前竞拍价")
                    return false
                }
                if (!store.getters.user_info.realName) {
                    router.push('/realName')
                    return false
                }
                if (!store.getters.user_info.payPassword) {
                    router.push('/editPwd')
                    return false
                }
                PwdShow.value.pwdopen = true
            } else {
                PwdShow.value.pwdopen = true
            }
        }
        const toastname = (item) => {
            Toast(item.name)
        }
        const copy = async () => {
            try {
                await toClipboard(Contentlist.value.assetId)
                Toast("复制成功")
            } catch (e) {
                console.error(e)
            }
        }
        const Cancel = async () => {
            collectionAuctionCancel().then(() => {

            })
        }
        return {
            openImg, Contentlist, Available, onLoad, copy, openPwd, PwdShow, paydata, user_info, toastname, page, VideoIndexOf, paytype, formData
        }
    }
}
</script>
<style lang="less" scoped>
.linercolor {
    font-size: 36px;
    width: fit-content;
    margin: 0px auto 20px;
    display: block;
}

.videoContainer {
    overflow: hidden;
    border-radius: 40px 40px 0px 0px;
    border: 1px solid #ffffff;

    .fullscreenVideo {
        width: 100%;
        //  width: 648px;
        height: 648px;
    }

    .img-status {
        position: absolute;
        right: 60px;
        top: 20px;

        img {
            width: 120px;
        }
    }
}

.videoContainers {
    position: relative;

    .img-status {
        position: absolute;
        right: 0px;

        img {
            width: 200px;
        }
    }

    .video {
        // width: 648px;
        // height: 648px;
        overflow: hidden;
        margin-top: 10px;

        .video {
            width: 100%;
            height: 348px;
        }
    }

    overflow: hidden;
    border-radius: 40px 40px 0px 0px;

    .fullscreenVideo {
        overflow: hidden;
        width: 100%;

        // height: 180px;
        source {
            width: 100%;
            border-radius: 40px 40px 0px 0px;
        }
    }
}

.innerPage {
    padding-bottom: 150px;

    .inner-img {
        overflow: hidden;
        width: 648px;
        height: 648px;
        background: linear-gradient(0deg, #161718, #4b4c4d);
        border: 2px solid #ffffff;
        border-radius: 80px;
        margin: 80px auto 20px;

        .img-bg {
            width: 100%;
            height: 100%;
            background-size: cover;
            // margin: 100px auto;
            position: relative;

            img {
                width: 100%;
                height: 100%;
            }

            .img-status {
                position: absolute;
                right: 0px;

                img {
                    width: 200px;
                }
            }
        }
    }

    .bottom-bg {
        background: url('../../assets/image/bottom.png');
        width: 660px;
        height: 220px;
        background-size: cover;
        margin: 0px auto;
    }

    .inner-title {
        display: flex;
        justify-content: center;
        align-items: center;
        text-align: center;

        h1 {
            font-size: 46px;
            font-family: Source Han Sans CN;
            font-weight: 400;
            color: #f8f8f8;
            line-height: 103px;
            margin: 0px;
        }
    }

    .Limit-warp {
        margin-right: 20px;

        span {
            font-size: 26px;
            font-family: Source Han Sans CN;
            font-weight: 400;
            line-height: 48px;
        }

        span:nth-child(1) {
            color: #444442;
            font-size: 26px;
            font-family: Source Han Sans CN;
            font-weight: 400;
            background: #f3e3bb;
            border-radius: 4px 0px 0px 4px;
            padding: 3px 12px;
        }

        span:nth-child(2) {
            padding: 3px 12px;
            background: #444442;
            border-radius: 4px;
            font-size: 26px;
            font-family: Source Han Sans CN;
            font-weight: 400;
            color: #f3e3bb;
            line-height: 48px;
        }
    }

    .colletion-authon {
        padding: 0px 18px;
        font-size: 34px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #ffffff;
        line-height: 140px;
        margin: 30px 20px 0px;
        height: 140px;
        background: #282a2c;
        border: 1px solid #ffffff;
        border-bottom: 0px;
        box-shadow: 0px 2px 30px 0px rgba(0, 0, 0, 0.35);
        border-radius: 20px;

        .right {
            display: flex;
            align-items: center;
            justify-content: flex-end;
            text-align: right;

            p {
                width: 80%;
                overflow: hidden;
                text-overflow: ellipsis;
            }

            img {
                width: 40px;
                margin-left: 20px;
            }

            text-align: right;

            span {
                text-align: center;
                font-size: 30px;
                font-family: Source Han Sans CN;
                font-weight: 400;
                color: #fefefe;
                background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
                -webkit-background-clip: text;
                -webkit-text-fill-color: transparent;
            }
        }
    }

    .collect-info {
        z-index: 1;
        margin-top: 50px;
        font-size: 36px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #f8f8f8;
        margin-left: 20px;
        padding-left: 40px;
        position: relative;
    }

    .collect-info::after {
        opacity: 0.8;
        z-index: -1;
        background-size: 100% 100%;
        width: 70px;
        height: 60px;
        top: -10px;
        left: 0;
        position: absolute;
        content: '';
        background-image: url('../../assets/image/point.png');
    }

    .Available {
        background: #282a2c;
        border-radius: 20px;
        margin: 30px 20px;
        padding: 20px 10px;

        .between-warp {
            position: relative;
            overflow: hidden;

            img {
                width: 100%;
                height: 180px;
            }
        }

        .img-warp {
            margin-top: 10px;
            // padding: 30px 10px;
            overflow: hidden;
            background: linear-gradient(0deg, #161718, #4b4c4d);
            border: 2px solid #ffffff;
            border-radius: 20px;
            background: linear-gradient(0deg, #161718, #4b4c4d);
            border: 2px solid #ffffff;
            border-radius: 20px;
        }
    }

    .story {
        background: #282a2c;
        border: 1px solid #ffffff;
        box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.35);
        border-radius: 20px;
        margin: 30px 30px;
        padding: 60px 30px;
        font-size: 28px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #ffffff;
        line-height: 48px;

        /deep/ img {
            width: 100%;
        }
    }

    .footer {
        display: flex;
        align-items: center;
        flex-flow: wrap;

        .price {
            font-size: 46px;
            font-family: Source Han Sans CN;
            font-weight: bold;
            color: #f8f8f8;
            margin-left: 50px;
        }

        .right {
            padding-right: 20px;
            text-align: right;
            display: flex;
            justify-content: flex-end;
            // &:deep(.van-button) {

            // }
            .sed {
                border: none;
                border-radius: 62px;
                width: 256px;
                height: 74px;
                background: #7d8184 !important;
                border-radius: 32px;

                span {
                    display: block;
                    font-size: 28px;
                    font-family: Source Han Sans CN;
                    font-weight: 400;
                    color: #ffffff;
                    line-height: 26px;
                }
            }

            .buy {
                border: none;
                background: linear-gradient(-90deg, #37dc6d, #34d1f9);
                border-radius: 62px;
                width: 256px;
                height: 74px;

                span {
                    display: block;
                    color: #f8f8f8;
                }
            }
        }
    }
}

&:deep(.van-popup) {
    background: #000 !important;
}

.gift-warp {
    padding-top: 50px;

    i {
        top: 20px;
        right: 20px;
        position: absolute;
        color: #fefefe;
        font-size: 60px;
    }

    img {
        display: block;
        width: 625px;
        height: 415px;
        margin: 50px auto 0px;
    }

    .box-btn {
        font-size: 32px;
        display: block;
        border: none;
        width: 448px;
        height: 80px;
        background: linear-gradient(-90deg, #37dc6d, #34d1f9);
        margin: 20px auto;
    }

    h1 {
        text-align: center;
        font-size: 48px;
        font-family: Source Han Sans CN;
        font-weight: bold;
        color: #f3e3bb;
        line-height: 42px;
        margin: 40px 0px;
    }

    width: 688px;
    height: 777px;
    background-image: url('../../assets/image/giftbg.png');
    background-size: 100% 100%;
}

&:deep(.van-cell-group) {
    margin: 56px 30px 0px;
    background: transparent;
    // min-height: 520px;
}

&:deep(.van-cell) {
    height: 100px;
    background: #282a2c;
    border: 1px solid #999;
    border-radius: 18px;
}

&:deep(.van-field__control) {
    font-size: 30px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #b9c4c7;
    opacity: 0.8;
}

.fiexd-footer {
    width: 750px;
    padding: 30px 0px;
    background: #282a2c;
    position: fixed;
    bottom: 0px;
    z-index: 999;
}

.fsb {
    display: flex;
    flex-flow: nowrap;
    justify-content: space-between !important;
    align-items: center;
    width: 100%;
}

.certificate {
    width: 100%;
    background: url(../../assets/image/certificate.png) no-repeat;
    background-size: 100% 100%;
    padding: 20px 0;
    margin-bottom: 20px;

    .certificate-img {
        width: 373px;
        height: 94px;
        display: block;
        margin: 30px auto;
    }

    h1 {
        width: 100%;
        text-align: center;
        padding: 20px 0;
        font-size: 61px;
        font-family: Source Han Serif SC;
        font-weight: bold;
        color: #FFCC90;
    }

    .certificate-time {
        p {
            width: 100%;
            text-align: center;
            display: block;
            font-weight: 400;
            font-size: 23px;
            font-family: Adobe Heiti Std;
            font-weight: normal;
            color: #FFCC90;
            line-height: 38px;
        }
    }

    .certificate-content {
        width: 100%;
        padding: 30px 0;
        display: flex;
        flex-flow: wrap;
        align-items: center;
        justify-content: center;

        div {
            width: 100%;
            display: flex;
            flex-flow: nowrap;
            justify-content: center;
            align-items: center;

            p:first-child {
                width: 40%;
                text-align: right;
                font-size: 28px;
                font-family: Source Han Serif SC;
                font-weight: bold;
                color: #FFFFFF;
                line-height: 63px;
            }

            p:last-child {
                width: 60%;
                text-align: left;
                font-size: 28px;
                font-family: Source Han Serif SC;
                font-weight: bold;
                color: #FFE2BF;
                line-height: 63px;
            }
        }
    }

    .certificate-code {
        width: 100%;
        text-align: center;

        img {
            margin: 20px auto;
            width: 272px !important;
            height: 272px !important;
            border: 4px solid #FFCC90;
            border-radius: 10px;
            padding: 15px;
        }

        p {
            font-size: 27px;
            font-family: Source Han Serif SC;
            font-weight: 600;
            color: #FFCC90;
            line-height: 28px;
        }
    }

    .borders {
        width: 555px;
        height: 29px;
        display: block;
    }

    .statement {
        font-size: 38px;
        font-family: Source Han Serif SC;
        font-weight: bold;
        color: #FFCC90;
        line-height: 79px;
        margin: 26px auto;
        text-align: center;
    }
}

.wp30 {
    width: 30%;
}

.buys {
    width: 680px;
    height: 88px;
    background: linear-gradient(-90deg, #37DC6D, #34D1F9);
    border-radius: 44px;
}
</style>